package com.example.farmer.Fragment.Message;

import android.os.Bundle;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.farmer.Database.ChatMessageDatabase;
import com.example.farmer.Entity.ChatMessage;
import com.example.farmer.R;

import java.util.List;

public class MessageDetailActivity extends AppCompatActivity {

    private ListView messagesListView;
    private ChatMessageAdapter detailAdapter;
    private ChatMessageDatabase database;
    private List<ChatMessage> chatMessages;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message_detail);

        messagesListView = findViewById(R.id.messagesListView);

        String sender = getIntent().getStringExtra("sender");
        List<ChatMessage> messagesBySender = getMessagesBySender(sender);

        detailAdapter = new ChatMessageAdapter(this, messagesBySender);
        messagesListView.setAdapter(detailAdapter);
    }

    private List<ChatMessage> getMessagesBySender(String sender) {
         database = new ChatMessageDatabase(this);
        chatMessages = database.loadMessagesBySender(sender);
        database.close(); // 记得关闭数据库连接
        return chatMessages;
    }

    // ChatMessageAdapter 类的实现（前面已有示例，此处省略）
}